# 列表
# list1 = [1,2,3,4,5]
#1 list1.append(6) #添加

#2 list1.insert(5,6)

#3 list1.remove(3) #删除
# list1.pop(-3)
# del list1[2]

#4 list1[1] = 8

#5 list1.index(8)

#6 for i in range(len(list1)):
#     print(list1[i])

# for i in list1:
#     print(i)


#7 li = [7,8,9]
# for a in li:
#     list1.append(a)
# print(list1)

#8 li2 = [10,11,12]
# list1 = list1 +li2
# list1.extend(li2)
# print(list1)

#9 print(list1[2:5:1])

#10 list1[2:3] = 13,14
# print(list1)

# 进阶
my_list = [3,"apple",9,"cherry",7,"banana",2,"date",5,"elderberry"]
#1 my_list.append("fig")
#2 del my_list[3]
#3 my_list[4] = "grape"
#4 my_list.index("cherry")
# print(my_list.index("cherry"))

#my_list.remove("banana")
#my_list[4] = "grape"
#print(my_list)
#index = my_list.index("cherry")
#print(index)

#5 for i in range(len(my_list)):
#     print(my_list[i])

#6 my_list.insert(6,"kiwi")
# print(my_list)

#7 m1 = my_list[2]
# print(m1)

#8 m2 = my_list[-2:-3:-1]
# m2 = my_list[-2]
# print(m2)

#9 m3 = my_list[2:7]
# print(m3)

#10 m4 = my_list[::-1]
# print(m4)
# strings = [el for el in my_list if isinstance(el,str)]
# # strings_sorted = sorted(strings)
# strings.sort()
# # print(strings_sorted)
# str_index = 0
# for i in range(len(my_list)):
#     if isinstance(my_list[i],str):
#         my_list[i] = strings[str_index]
#         str_index += 1
# print(my_list)

#12 numbers = [nu for nu in my_list if isinstance(nu,int)]
# numbers_str = ['three','nine','seven','two','fix']
# print(numbers_str)
# str_index = 0
# for i in range(len(my_list)):
#     if isinstance(my_list[i],int):
#         my_list[i] = numbers_str[str_index]
#         str_index += 1
# print(my_list)


# # 字典
person_info = {
    "name": "Alex",
    "age": 30,
    "country": "USA",
    "language": ["English", "Spanish"],
    "is_student": False
}
#1 print("name值:",person_info["name"])

#2 person_info["age"] = 31
#  print(person_info)

#3 person_info["height"] = 175
#  print(person_info)

#4 del person_info["is_student"]
#  print(person_info)

#5 for item in person_info.items():
#     print(item)

#6 if 'email' not in person_info:
#  person_info["email"] = "alex@example.com"
#  print(person_info)

#7 person_info['language'] = 'English'
#  print(person_info)

#8 lang_length = len(person_info["language"])
#  print(lang_length)

#9 person_info["language"].append('Chinese')
#  print(person_info["language"])

#10 for i in range(1,4):
#     key = f"hobby{i}"
#     value = f"hobby{i}值"
#     person_info[key] = value
# print(person_info)

# 进阶
employees = {
    101: {
        "name": "Alice",
        "age": 30,
        "gender": "Female",
        "position": "Data Scientist",
        "team": "Research",
        "salary_history": [70000, 80000, 90000]
    },
    # 更多员工数据...
}
#1 new_employee_id = 102
# new_employee = {
#     "name":"Diana",
#     "age":30,
#     "gender":"Female",
#     "position":"Data Scientist",
#     "team":"Research",
#     "salary_history": [70000, 80000, 90000]
# }
# employees[new_employee_id] = new_employee
# print(employees)

#2 employees_id_to_delete = 101
# if employees_id_to_delete in employees:
#     del employees[employees_id_to_delete]
# print(employees)

#3 employees[101]["age"] = 31
# print(employees)

#4 employees[101]["salary_history"].append(95000)
# print(employees[101]["salary_history"])

#5 avg_salary = sum(employees[101]["salary_history"]) / len(employees[101]["salary_history"])
# print(avg_salary)

#6 for emp_id, emp_info in employees.items():
#     if emp_info.get("age",0) > 25:
#         print(f"ID： {emp_id},姓名：{emp_info['name']}")

#7 for emp_info in employees.values():
#     if "salary_history" in emp_info and emp_info["salary_history"]:
#         latest_salary = emp_info["salary_history"][-1]
#         emp_info["bonus"] = int(latest_salary * 0.1)
# print("员工101的奖金：",employees[101]["bonus"])

#8 employees[101]["position"] = "Senior Data Scientist"
# print(employees)

#9 for emp_info in employees.values():
#     if "gender" in emp_info:
#         del emp_info["gender"]
# print("员工101移除gender后的信息：",{k:v for k,v in employees[101].items() if k !="gender"})

#10 name_position_dict ={}
# for emp_id,emp_info in employees.items():
#     name_position_dict[emp_id] = {
#         "name" : emp_info["name"],
#         "position" : emp_info["position"]
#     }
# print("仅包含姓名和职位的字典：",name_position_dict)

#字符串
#基础
s = "Hello, Python world!"
#1 length = len(s)
#2 o_count = s.count("o")
#3 upper_s = s.upper()
#4 lower_s = s.lower()
#5 python_pos = s.find("Python")
#6 replaced_s = s.replace("world", "universe")
#7 starts_with_hello = s.startswith("Hello")
#8 ends_with_excl = s.endswith("!")
#9 split_by_comma = s.split(",")
#10 stripped_s = s.strip("!")
#11 reversed_s = s[::-1]
#12 python_slice = s[7:13]
#13 removed_hello = s.replace("Hello, ", "")
#14 concatenated = "Hello, " + "World!"
#15 f_string = f"Python {2021}"
# print(f_string)
#16 a_pos = s.find('a')
#17 e_last_pos = s.rfind('e')
#18 space_count = s.count(' ')
#19 for char in s:
#     print(char, end=' ')
# print()
#20 char_list = list(s)
# print(char_list)
#21 sorted_chars = sorted(list(s))
# sorted_s = ''.join(sorted_chars)
# print(sorted_chars)
#22 is_digit = s.isdigit()
# print(is_digit)
#23 words = ['Hello,', 'Python', 'World!']
# joined = ' '.join(words)
#24 formatted1 = "Number: {}".format(100)
# formatted2 = f"Number: {100}"
# formatted = "Number: %d" % 100
#25 is_all_lower = s.islower()
#26 is_all_upper = s.isupper()
#27 numbers = [1, 2, 3]
# num_str = '-'.join(map(str, numbers))
#28 o_positions = [i for i, char in enumerate(s) if char == 'o']
#29 first_o_replaced = s.replace('o', 'O', 1)
#30 inserted = s[:7] + "amazing " + s[7:]
# print(f"30. 插入'amazing '后: {inserted}")